package com.woniuxy.consumer.service.impl;

import com.woniuxy.commons.entity.PageBean;
import com.woniuxy.commons.entity.UserDetails;
import com.woniuxy.commons.utils.ResponseResult;
import com.woniuxy.commons.utils.ResultStatus;
import com.woniuxy.consumer.mapper.UserdetailsMapper;
import com.woniuxy.consumer.service.DetailsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author author
 * @create 2021-11-15 19:41
 */
@Service
public class DetailsServiceImpl implements DetailsService {

    @Resource
    private UserdetailsMapper userdetailsMapper;

    @Override
    public ResponseResult<PageBean<UserDetails>> selectUserDetailsByPageService(UserDetails userDetails, int pageIndex, int pageSize) {
        PageBean<UserDetails> pageBean = new PageBean<>();
        List<UserDetails> userDetailsList = userdetailsMapper.selectUserDetailsByPage(userDetails, pageIndex, pageSize);

        int i = userdetailsMapper.selectCountUserDetailsByPage(userDetails);
        pageBean.setBeanList(userDetailsList);
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(i);

        ResponseResult<PageBean<UserDetails>> result = new ResponseResult<>();
        result.setCode(200);
        result.setMessage("成功");
        result.setStatus(ResultStatus.SELECT_YES);
        result.setData(pageBean);
        return result;
    }

    @Override
    public UserDetails selectUserByUidService(String uid) {
        return userdetailsMapper.getUserByUid(uid);
    }
}
